package jku.semtech.common;

import java.util.HashMap;
import java.util.Map;

public class Team {
	private String teamName;
	private String nickName;
	private String managerName;
	private String ground;
	private int stadiumCapacity;
	private Map<String, Player> players;

	public Team(String teamName, String nickName, String managerTitle,
			String ground, int stadiumCapacity) {
		this.setTeamName(teamName);
		this.setNickName(nickName);
		this.setManagerTitle(managerTitle);
		this.setGround(ground);
		this.setStadiumCapacity(stadiumCapacity);
		this.players = new HashMap<String, Player>();
	}

	// methods
	public void addPlayer(Player player) {
		players.put(player.getName(), player);
		System.out.println("Player " + player.getName() + " added");
	}

	public void removePlayer(Player player) {
		players.remove(player);
		System.out.println("Player " + player.getName() + " removed");
	}

	public int getAllGoals() {
		int goals = 0;
		
		//iterate over each player to sum up the team goals
		for(Player p :  players.values()) {
			goals += Integer.parseInt(p.getAverageGoals());
		}
		return goals;
	}

	// properties
	public String getTeamName() {
		return teamName;
	}

	public void setTeamName(String teamName) {
		this.teamName = teamName;
	}

	public String getManagerName() {
		return managerName;
	}

	public void setManagerTitle(String managerName) {
		this.managerName = managerName;
	}

	public String getGround() {
		return ground;
	}

	public void setGround(String ground) {
		this.ground = ground;
	}

	public int getStadiumCapacity() {
		return stadiumCapacity;
	}

	public void setStadiumCapacity(int stadiumCapacity) {
		this.stadiumCapacity = stadiumCapacity;
	}

	public Map<String, Player> getPlayers() {
		return players;
	}

	public void setPlayers(Map<String, Player> players) {
		this.players = players;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
}
